<template>
  <div>{{ curValue||value }}</div>
</template>
<script>
import { SLMDict } from '@/api/dataDict'
export default {
  name: 'CDictRangeView',
  props: {
    dictTypeCode: {
      type: String,
      default: ''
    },
    domainCode: {
      type: String,
      default: ''
    },
    appCode: {
      type: String,
      default: ''
    },
    value: {
      type: [String, Number],
      default: ''
    }
  },
  data() {
    return {
      curValue: ''
    }
  },
  watch: {
    value: {
      handler(v) {
        this.getDict()
      },
      immediate: true
    }
  },
  methods: {
    getDict() {
      if (!this.dictTypeCode) return
      SLMDict(this.dictTypeCode, this.domainCode, this.appCode).then(res => {
        // const v = (this.value || '').toString().split(',')
        const v = /^\d+$/.test(this.value) ? this.value.toString().split(',') : this.value.split(',')
        const str = []
        for (const item of res.data) {
          if (v.includes(item.dictCode)) {
            str.push(item.dictName)
          }
        }
        this.curValue = str.join(',')
      })
    }
  }
}
</script>
